<!DOCTYPE html>
<html>
    <body>
        <script type="module">
            import * as duckdb from './duckdb-browser.mjs';

            (async () => {
                try {
                    const DUCKDB_CONFIG = await duckdb.selectBundle({
                        mvp: {
                            mainModule: './duckdb.wasm',
                            mainWorker: './duckdb-browser.worker.js',
                        },
                        eh: {
                            mainModule: './duckdb-eh.wasm',
                            mainWorker: './duckdb-browser-eh.worker.js',
                        },
                    });

                    const logger = new duckdb.ConsoleLogger();
                    const worker = new Worker(DUCKDB_CONFIG.mainWorker);
                    const db = new duckdb.AsyncDuckDB(logger, worker);
                    await db.instantiate(DUCKDB_CONFIG.mainModule, DUCKDB_CONFIG.pthreadWorker);

                    const conn = await db.connect();
                    await conn.query(`SELECT count(*)::INTEGER as v FROM generate_series(0, 100) t(v)`);

                    await conn.close();
                    await db.terminate();
                    await worker.terminate();
                } catch (e) {
                    console.error(e);
                }
            })();
        </script>
    </body>
</html>
